#pragma once

#include "CXcpObjectBase.h"
#include "CXcpObjectThreadSafeAddRefPolicy.h"
#include "ICompositor.h"

class CMetaCompositor;


class CCompositor :
	public CXcpObjectBase<ICompositor,CXcpObjectThreadSafeAddRefPolicy>
{

public: 
	void SetContentIsReadyToPresent(XBOOL fContentIsReadyToPresent);
	virtual void SetShutdownEvent(struct IPALEvent * pShutdownEvent);
	struct IPALGraphicsDevice * GetGraphicsDevice();
	struct IPALPresentMethod * GetPresentMethod();
	HRESULT PickUpCurrentDrawList();
	XBOOL HasWaitingToDrawList();
	XBOOL HasDrawCommands();

protected: 
	CCompositor(CMetaCompositor *);
	virtual ~CCompositor();
	HRESULT Initialize(struct IPALPresentMethod * pIPresentMethod);
	HRESULT AddCommand(struct IDrawCommand * pCommand);
	HRESULT SubmitCommands();
	HRESULT TickCommands();
	HRESULT RenderCommands();
	void CleanupLists();
	CMetaCompositor * GetMetaCompositor();
	XBOOL IsContentReadyToPresent();
private: 
	struct IPALEvent * m_pShutdownEvent;
	CMetaCompositor * m_pMetaCompositorNoRef;
	HRESULT AddListForCleanup(xvector<IDrawCommand *> * pDrawList);
	xvector<IDrawCommand *> * m_pBuildList;
	xvector<IDrawCommand *> * m_pWaitingToDrawList;
	xvector<IDrawCommand *> * m_pDrawList;
	xvector<xvector<IDrawCommand *> *> m_ListsToDispose;
	struct IPALCriticalSection * m_pCleanupListLock;
	struct IPALPresentMethod * m_pIPresentMethod;
	XBOOL m_fContentIsReadyToPresent;


};